package com.edu.demo.controller;

import com.edu.demo.config.OssConfig;
import com.edu.demo.config.FaceConfig;
import com.edu.demo.entity.dto.FileUploadDTO;
import com.edu.demo.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.Map;

@Api(tags = "人脸融合")
@RestController
@RequestMapping("/face")
public class FaceController {

    @Autowired
    private OssConfig ossConfig;
    @Autowired
    private FaceConfig faceConfig;

    @ApiOperation(value = "人脸动漫画")
    @PostMapping("/upload/faceToAnimated")
    public Result<Map> faceToAnimated(
            @RequestParam("face") MultipartFile face,
            @RequestParam("文件类型")String fileType) throws Exception {
        //数据库保存里面
        String facePath = ossConfig.putObject(face, fileType);
        facePath = "https://"+ossConfig.getBucketName()+"."+ossConfig.getEndpoint()+"/"+facePath;
        //合成人脸
        Map map = faceConfig.faceToAnimated(facePath);
        return Result.success(map);
    }
}
